package com.example.sys2.controller;


import com.example.sys2.common.result.Result;
import com.example.sys2.common.result.ResultUtils;
import com.example.sys2.entity.Desk;
import com.example.sys2.service.IDeskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liruirui
 * @since 2023-09-21
 */
@RestController
@RequestMapping("/desk")
public class DeskController {


    @Autowired
    IDeskService service;

    @GetMapping("/getList")
    public Object getList(){
        return ResultUtils.returnSuccessLayui(service.list(),service.list().size());
    }


    @GetMapping("/getById")
    public Result getById(Integer id){
        Desk desk = service.getById(id);
        return (Result) ResultUtils.returnDataSuccess(desk);
    }
    @PostMapping("/add")
    public Object add(Desk Desk){
        if(service.save(Desk)){
            return  ResultUtils.returnSuccess();
        }else{
            return  ResultUtils.returnFail();
        }
    }


    @PostMapping("/update")
    public Object update(Desk Desk){
        if(service.updateById(Desk)){
            return  ResultUtils.returnSuccess();
        }else{
            return  ResultUtils.returnFail();
        }
    }

    @PostMapping("/delete")
    public Object delete(Desk Desk){
        if(service.removeById(Desk.getId())){
            return  ResultUtils.returnSuccess();
        }else{
            return  ResultUtils.returnFail();
        }
    }

}